package com.cybertron.ironhide.manage.action;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import com.cybertron.ironhide.manage.common.base.BaseAction;
import com.cybertron.ironhide.manage.domain.Adver;
import com.cybertron.ironhide.manage.service.AdverService;

public class AdverAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8147289670319391486L;

	@Resource
	private AdverService adverService;

	private Adver adver;

	private List<Adver> advers;

	private File file;

	private String fileFileName;

	public String list() {
		advers = adverService.selectBySelective(adver, pager);
		return LIST;
	}

	public String add() {
		return ADD;
	}

	public String doAdd() throws IOException {
		adver.setCreateDate(new Date());
		adverService.insertSelective(adver);
		return ajaxSuccess("广告添加成功", "index-list", "index-list-box",
				CLOSE_CURRENT);
	}

	public String edit() {
		adver = adverService.selectByPrimaryKey(adver.getId());
		return EDIT;
	}

	public String doEdit() throws IOException {
		adver.setModifyDate(new Date());
		adverService.updateByPrimaryKeySelective(adver);
		return ajaxSuccess("广告编辑成功", "index-list", "index-list-box",
				CLOSE_CURRENT);
	}

	public String delete() {
		adverService.deleteByPrimaryKey(adver.getId());
		return ajaxSuccess("广告删除成功", "index-list", "index-list-box");
	}

	public Adver getAdver() {
		return adver;
	}

	public void setAdver(Adver adver) {
		this.adver = adver;
	}

	public List<Adver> getAdvers() {
		return advers;
	}

	public void setAdvers(List<Adver> advers) {
		this.advers = advers;
	}

	public AdverService getAdverService() {
		return adverService;
	}

	public void setAdverService(AdverService adverService) {
		this.adverService = adverService;
	}

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	public String getFileFileName() {
		return fileFileName;
	}

	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}

}
